package com.thoughtmechanix.organization.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.thoughtmechanix.organization.model.Organization;
import com.thoughtmechanix.organization.repository.OrganizationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;
import java.util.Random;
import java.util.UUID;

@Service
public class OrganizationService {

    @Autowired
    private OrganizationRepository organizationRepository;



//    @HystrixCommand
    public Organization getOrg(String organizationId){
        Optional<Organization> byId = organizationRepository.findById(organizationId);
        return byId.get();
    }

    public void saveOrg(Organization org){
        org.setId(UUID.randomUUID().toString());
        organizationRepository.save(org);
    }

    public void updateOrg(Organization org){
        organizationRepository.save(org);
    }

    public void deleteOrg(Organization org){
        organizationRepository.delete(org);
    }

}
